// textContent
// innerText //获取用户能看得到的元素变成文本
// textContent //获取所有元素变成文本
//获取元素焦点
 
let getSelection=window.getSelection()

let cursor={
    SetCursorPosition: (dom,setStart,setEnd )=> {
    let s = getSelection,
      r = document.createRange();
    if (dom.innerText != "") {
      r.setStart(dom, setStart);
      r.setEnd(dom, setEnd);
    } else {
      r.selectNodeContents(dom);
    }
    // document.execCommand('delete', false, null);
    s.removeAllRanges();
    s.addRange(r);
  },
  
  base: () => {
    let selection = getSelection, //获取选区
      range = selection.getRangeAt(0) //获取一个选区
    let  positionDom = range.endContainer //获取光标所在位置
      let positionIndex = range.endOffset; //获取光标所在节点
    // if (typeof positionDom == "string") {
    //   positionDom = positionDom;
    // } else if (typeof positionDom == "object") {
    //   positionDom = positionDom.data || positionDom.textContent;
    // } else { 
    //   positionDom = "";
    // }
    return { range, positionIndex, positionText: positionDom };
  },
  stop: bool => {
    if (window) {
      window.event.returnValue = bool;
      return bool;
    } 
  },
 
}

//获取
// document.onselectionchange = () => {
//   console.log(document.getSelection());
// }

//删除某dom元素
// function delDom(ele, i) {
//   const delLen = 1;
//   return ele.splice(i, delLen);
// }
// keyCode==191

//  document.onkeydown = function(e) {
//    //事件对象兼容
//    let e1 = e || event || window.event || arguments.callee.caller.arguments[0]
//    console.log(e)
//             //键盘按键判断:左箭头-37;上箭头-38；右箭头-39;下箭头-40
            
//         }


export {cursor}